package cn.al2.util;

import cn.al2.util.constant.Constants;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class GenerateUtil {

    private GenerateUtil() {
    }


    private static class GenerateUtilHolder {
        private static final GenerateUtil instance = new GenerateUtil();
    }

    public static GenerateUtil getInstance() {
        return GenerateUtilHolder.instance;
    }


    public List<String> product() {
        List<String> list = new ArrayList<>();

        String chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_=+[{]}\\|;:'\",<.>/? ";

        for (int i = 0; i < Constants.productLogSize; i++) {

            Random random = new Random();


            int length = (int) (Math.random() * Constants.productLogMAX) + Constants.productLogMIN; // 生成200到
//            System.out.println(length);
            StringBuilder sb = new StringBuilder(length);
            for (int j = 0; j < length; j++) {
                int index = random.nextInt(chars.length());
                sb.append(chars.charAt(index));
            }
            list.add(sb.toString() + "=====================\n");
        }
        return list;
    }

    public List<String> staticProduct() {
        List<String> list = new ArrayList<>();

        String filePath = "src.txt"; // 文件路径

        try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {
            String line;
            int count = 0;
            while ((line = br.readLine()) != null) {
                list.add(line);
                count++;
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return list;
    }
}
